﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using Telerik;
using Telerik.Web.UI;

namespace TelerikHelper
{
    [ToolboxData("<{0}:AdvancedRadGrid runat=server></{0}:AdvancedRadGrid>")]
    public class AdvancedRadGrid : RadGrid
    {
        public bool ArabicInterface
        {
            get
            {
                if(this.ViewState["ArabicInterface"]==null)
                {
                    this.ViewState["ArabicInterface"] = false;
                }
                return (bool)this.ViewState["ArabicInterface"];
            }
            set
            {
                this.ViewState["ArabicInterface"] = value;
            }
        }


        protected override void OnItemCreated(GridItemEventArgs e)
        {
            if (this.ArabicInterface)
            {
                //pager
                if (e.Item is GridPagerItem)
                {
                    GridPagerItem item = e.Item as GridPagerItem;
                    Button changePageSize = (Button)e.Item.FindControl("ChangePageSizeLinkButton");
                    if (changePageSize != null)
                    {
                        changePageSize.Text = "تغيير";
                    }
                    Button goTO = (Button)e.Item.FindControl("GoToPageLinkButton");
                    if (goTO != null)
                    {
                        goTO.Text = "تغيير";
                    }
                    Label itesNumberLabel = (Label)e.Item.FindControl("ChangePageSizeLabel");
                    if (itesNumberLabel != null)
                    {
                        itesNumberLabel.Text = "          عدد الصفوف :";
                    }
                    Label goTOLabel = (Label)e.Item.FindControl("GoToPageLabel");
                    if (goTOLabel != null)
                    {
                        goTOLabel.Text = "صفحة :";
                    }
                    Label ofLabel = (Label)e.Item.FindControl("PageOfLabel");
                    if (ofLabel != null)
                    {
                        ofLabel.Text = "من " + item.Paging.PageCount.ToString();
                    }
                }


                //filters
                GridFilterMenu menu = this.FilterMenu;
                foreach (RadMenuItem item in menu.Items)
                {    //change the text for the "StartsWith" menu item  
                    if (item.Text.ToLower() == "NoFilter".ToLower())
                    {
                        item.Text = "بدون تصفية";
                    }
                    else if (item.Text.ToLower() == "contains".ToLower())
                    {
                        item.Text = "يحتوي";
                    }
                    else if (item.Text.ToLower() == "DoesNotContain".ToLower())
                    {
                        item.Text = "لايحتوي";
                    }
                    else if (item.Text.ToLower() == "StartsWith".ToLower())
                    {
                        item.Text = "يبداء ب";
                    }
                    else if (item.Text.ToLower() == "EndsWith".ToLower())
                    {
                        item.Text = "ينتهي ب";
                    }
                    else if (item.Text.ToLower() == "EqualTo".ToLower())
                    {
                        item.Text = "يساوى";
                    }
                    else if (item.Text.ToLower() == "NotEqualTo".ToLower())
                    {
                        item.Text = "لايساوي";
                    }
                    else if (item.Text.ToLower() == "GreaterThan".ToLower())
                    {
                        item.Text = "اكبر من";
                    }
                    else if (item.Text.ToLower() == "LessThan".ToLower())
                    {
                        item.Text = "اصغر من";
                    }
                    else if (item.Text.ToLower() == "GreaterthanOrEqualTo".ToLower())
                    {
                        item.Text = "اكبر من او يساوى ";
                    }
                    else if (item.Text.ToLower() == "LessthanOrEqualTo".ToLower())
                    {
                        item.Text = "اصغر من او يساوي";
                    }
                    else if (item.Text.ToLower() == "Between".ToLower())
                    {
                        item.Text = "بين";
                    }
                    else if (item.Text.ToLower() == "NotBetween".ToLower())
                    {
                        item.Text = "ليس بين";
                    }
                    else if (item.Text.ToLower() == "IsEmpty".ToLower())
                    {
                        item.Text = "فارغ";
                    }
                    else if (item.Text.ToLower() == "NotIsEmpty".ToLower())
                    {
                        item.Text = "غير فارغ";
                    }
                    else if (item.Text.ToLower() == "ISNull".ToLower())
                    {
                        item.Text = "لايحتوى قيمة";
                    }
                    else if (item.Text.ToLower() == "NotISNull".ToLower())
                    {
                        item.Text = "يحتوى قيمة";
                    }
                }

            }
            base.OnItemCreated(e);
        }
    }
}

